/*
 * @lc app=leetcode.cn id=643 lang=cpp
 *
 * [643] 子数组最大平均数 I
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    double findMaxAverage(vector<int> &nums, int k)
    {
        double ans = INT_MIN;
        double tmp = std::accumulate(nums.begin(), nums.begin() + k, 0);
        ans = std::max(ans, tmp);

        for (int r = k; r < nums.size(); r++)
        {
            tmp += nums[r] - nums[r - k];
            ans = std::max(ans, tmp);
        }

        return ans / k;
    }
};
// int main(int argc, char const *argv[])
// {
//     vector<int> V = {1, 12, -5, -6, 50, 3};
//     cout << Solution().findMaxAverage(V, 4) << endl;
//     return 0;
// }

// @lc code=end
